<?php
include('include/config.inc.php');
$branchArray          = array();
$partyArray         = array();
if(isset($_POST['companyName']))
{
  $address =addslashes($_POST['address']);
  $insertParty = "INSERT INTO party (companyName,contactPerson1,contactPerson2,contactPerson3,phoneNo,branchId,address,city,mobile1,mobile2,mobile3,email)
                        VALUE('".$_POST['companyName']."','".$_POST['contactPerson1']."','".$_POST['contactPerson2']."','".$_POST['contactPerson3']."',
                              '".$_POST['phoneNo']."',".$_POST['branchId'].",'".$address."','".$_POST['city']."','".$_POST['mobile1']."',
                              '".$_POST['mobile2']."','".$_POST['mobile3']."','".$_POST['email']."')";
  $insertPartyResult = mysql_query($insertParty);
   echo $lastInserId =  mysql_insert_id();
   exit();
}
 // after post : end
  
$branch = "SELECT branchId,branchName
             FROM branch";
$branchResult = mysql_query($branch);
$a = 0;  
while ($branchRow = mysql_fetch_array($branchResult))
{
	 if($a == 0 || (isset($_REQUEST['branchId']) && $_REQUEST['branchId'] == $branchRow['branchId']))
    $branchSelected = $branchRow['branchId']; 
    
	$branchArray['branchId'][$a]   = $branchRow['branchId'];
	$branchArray['branchName'][$a] = $branchRow['branchName'];
	$a++;
}

$party = "SELECT partyId,companyName
            FROM party";
$partyResult = mysql_query($party);
$b = 0;  
while ($partyRow = mysql_fetch_array($partyResult))
{
	 if($b == 0 || (isset($_REQUEST['partyId']) && $_REQUEST['partyId'] == $partyRow['partyId']))
    $partySelected = $partyRow['partyId']; 
    
	$partyArray['partyId'][$b]   = $partyRow['partyId'];
	$partyArray['companyName'][$b] = $partyRow['companyName'];
	$b++;
}
$smarty->assign("branchArray",$branchArray);
 $smarty->display("partyAj.tpl");
?>